﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace Maticsoft.DAL.CarrefourCover
{
    public partial class Vote
    {
        public int GetTodayVoteCount( int uid )
        {
            SqlParameter[] parameters = 
            {
                new SqlParameter("@id", SqlDbType.Int,4),
                new SqlParameter("@date", SqlDbType.DateTime2 )
            };
            parameters[0].Value = uid;
            parameters[1].Value = DateTime.Today;
            return Convert.ToInt32( DBUtility.DbHelperSQL.GetSingle( "SELECT COUNT(1) FROM VOTE WHERE AccountId = @id AND CreateTime > @date", parameters ) );
        }

        public int GetTodayVoteTargetCount( int uid, int targetid )
        {
            // new Model.CarrefourCover.Vote().VoteTargetId
            SqlParameter[] parameters = 
            {
                new SqlParameter("@id", SqlDbType.Int,4),
                new SqlParameter("@targetid", SqlDbType.Int,4),
                new SqlParameter("@date", SqlDbType.DateTime2 )
            };
            parameters[0].Value = uid;
            parameters[1].Value = targetid;
            parameters[2].Value = DateTime.Today;
            return Convert.ToInt32( DBUtility.DbHelperSQL.GetSingle( "SELECT COUNT(1) FROM VOTE WHERE AccountId = @id AND CreateTime > @date AND VoteTargetId = @targetid", parameters ) );
        }

        public int GetTotalVoteCount( int uid )
        {
            SqlParameter[] parameters = 
            {
                new SqlParameter("@id", SqlDbType.Int,4)
            };
            parameters[0].Value = uid;
            parameters[1].Value = DateTime.Today;
            return Convert.ToInt32( DBUtility.DbHelperSQL.GetSingle( "SELECT COUNT(1) FROM VOTE WHERE AccountId = @id", parameters ) );
        }
    }
}
